<template>
  <div>
    <Navigation ref="nav_ref" @callbackComponent="callbackComponent"/>
    <!-- 导航栏 -->
    <h1 class="text-hide ny_banner" v-for="(item,index) in banner" :key="index"
        :style="{background:'url('+item.url+') no-repeat center  50%/cover'}">公司新闻</h1>
    <div class="container ny_content"  v-wechat-title='article_list.title'>
      <div class="ny_nav">
        <div class="ny_nav_h">
          <div @click="tap"  style="cursor:pointer">
            <h2>咨讯动态</h2>
            <p>DYNAMIC INFORMATION</p>
          </div>
        </div>
        <div class="ny_nav_dqwz" @click="tap"  style="cursor:pointer">
          当前位置：<span class="hidden-xs" >咨讯动态></span>{{ titleType }}
        </div>
      </div>
      <div class="ny_view">
        <div id="news_view">
          <div class="page-header">
            <h3>
              {{ article_list.title }}
            </h3>
          </div>
          <div class="news_info">
            <b>时间：</b>  {{ article_list.create_time }}
            <b>浏览量：</b>{{ article_list.hits }}
          </div>
          <div class="news_content" v-html="article_list.content"></div>
          <div class="news_page">
            <p class="news_pre news_laiyuan" v-if="article_list.source">【来源:{{ article_list.source }}】</p>
            <a style="cursor:pointer" :class="article_list.up == null ? 'news_pre news_none' : 'news_pre'" @click="getNewDetail(article_list.up)"><b>上一篇:</b>{{ article_list.up == null ? '没有了' : article_list.up.title }}</a>
            <a style="cursor:pointer" :class="article_list.down == null ? 'news_pre news_none' : 'news_pre'" @click="getNewDetail(article_list.down)"><b>下一篇:</b>{{ article_list.down == null ? '没有了': article_list.down.title }}</a>
          </div>
        </div>
      </div>
    </div>
    <Footer/>
  </div>
</template>

<script>
import Navigation from '../../../components/Navigation'
import Footer from '../../../components/Footer'

export default {
  name: 'dynamic_detail',
  components: {
    Navigation,
    Footer
  },
  data () {
    return {
      banner: [],
      article_list:[],
      article_id:'',
      titleType:'',
    }
  },
  created () {
    this.article_id = sessionStorage.getItem('new_id')
    this.getArticleShow()
    this.getArticleType()

  },
  methods: {
    async getArticleType () {
      let newTypeList = [];
      const {data: res} = await this.$http.get('home/article_type_list')
      if (res.code !== 200) return false
      let index = (sessionStorage.getItem('currentValue'))
      newTypeList.push(res.data.list)
      let newStr = JSON.parse(JSON.stringify(newTypeList))
      for (let i in newStr) {
       this.titleType = (newStr[i][index])
      }
    },
    //点击
    tap(){
      this.$router.push('/dynamic');
    },
    async getArticleShow(){
      const {data: res} = await this.$http.get('home/show_article/'+this.article_id)
      if (res.code !== 200) return false
      this.article_list = res.data.list
      document.querySelector('meta[name="keywords"]').setAttribute('content', res.data.list.keyword)
      document.querySelector('meta[name="description"]').setAttribute('content', res.data.list.description)
    },
    callbackComponent (params) {
      params.function && this[params.function](params.data)
    },
    getBannerList (data) {
      this.banner = data.image
    },
    async getNewDetail(data){
      if (data === null) return false;
      const {data: res} = await this.$http.get('home/show_article/'+data.id)
      if (res.code !== 200) return false
      this.article_list = res.data.list
      document.querySelector('meta[name="keywords"]').setAttribute('content', res.data.list.keyword)
      document.querySelector('meta[name="description"]').setAttribute('content', res.data.list.description)
    }
  },
}
</script>

<style scoped>

</style>
